package com.badibadi.activity;

import com.badibadi.activity.BaseActivity.OnMyDialogeClistener;
import com.badibadi.infos.UserInfoModel;
import com.badibadi.mytools.UserDataSet;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;

import android.os.Bundle;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ModifyTheDataActivity extends BaseActivity implements OnClickListener{

	private EditText et_Data;
	private Button btn_Save;
	private int id;
	/**存放点击保存后返回的数据*/
    private String rel="";
    /**保存按返回键返回的数据*/
    private String resh="";
    private UserInfoModel userInfoModel;
    private UserDataSet userDataSet;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_modify_the_data);
		
		 
		init();
	}

	protected void init() {
		// TODO Auto-generated method stub
	//	getIntent().getStringExtra(name);
		resh="";
		userInfoModel=(UserInfoModel) getIntent().getSerializableExtra("userInfoModel");
		userDataSet=new UserDataSet(ModifyTheDataActivity.this);
		this.findViewById(R.id.returnbtn).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				returnData(true);
				Intent intent=new Intent(ModifyTheDataActivity.this,MyDataActivity.class);
				startActivity(intent);
			}
		});
		id=getIntent().getIntExtra("id",-1);
		et_Data=(EditText)this.findViewById(R.id.Data_xiugai);
		btn_Save=(Button)this.findViewById(R.id.btn_Save);
		btn_Save.setOnClickListener(this);
		TextView title=(TextView)this.findViewById(R.id.title);
		switch(id)
		{
		case 1:
			et_Data.setText(getIntent().getStringExtra("KEY1"));
			//修改名称
			title.setText(getResources().getString(R.string.Designation));
			break;
		case 2:
			//修改邮箱
			et_Data.setText(getIntent().getStringExtra("KEY2"));
			title.setText(getResources().getString(R.string.Mail));
			break;
		case 3:
			et_Data.setText(getIntent().getStringExtra("KEY3"));
			title.setText(getResources().getString(R.string.Sex));
			
			break;
		case 4:
			et_Data.setText(getIntent().getStringExtra("KEY4"));
			title.setText(getResources().getString(R.string.MobilePhoneNumber));
			break;
//		case 5:
////			et_Data.setText(getIntent().getStringExtra("KEY5"));
////			title.setText(getResources().getString(R.string.from));
//			setFromDialog(ModifyTheDataActivity.this);
//			break;
//		case 6:
//			et_Data.setText(getIntent().getStringExtra("KEY6"));
//			break;
		}
		resh=et_Data.getText().toString().trim();
	}


	

	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.modify_the_data, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId())
		{
		case R.id.btn_Save:
			switch(id)
			{
			case 1:
				userInfoModel.setNickName(et_Data.getText().toString().trim());
				
				break;
			case 2:
				userInfoModel.setEmail(et_Data.getText().toString().trim());
				
				break;
			case 4:
				userInfoModel.setPhone(et_Data.getText().toString().trim());
			
				break;
			}
			
				returnData();
			
			
			break;
		}
	}
	/**
	 * 
	 * 
	 */
	protected void returnData()
	{   
		Intent it = new Intent(ModifyTheDataActivity.this,ExpertApplyForActivity.class);
//		rel=et_Data.getText().toString().trim();
		it.putExtra("userInfoModel", userInfoModel);
		UserDataSet userDataSet=new UserDataSet(ModifyTheDataActivity.this);
		userDataSet.UserDataSet(userInfoModel, 0, "", false);
		
//		setResult(((id*10)+id), it);
		startActivity(it);
		finish();
		 overridePendingTransition(R.anim.slide_left,
					R.anim.slide_right);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Utils.ExitPrgress(ModifyTheDataActivity.this);
		
	}
}
